<template>
  <div>
    <a-form-model>
      <a-form-model-item label="修改id">
        <a-input disabled :value="id" />
      </a-form-model-item>
      <a-form-model-item label="内容">
        <a-input v-model="content" />
      </a-form-model-item>
      <a-form-model-item>
        <a-button @click="editSbt">
          保存
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
export default {
  name: 'Edit',
  asyncData (ctx) {
    const id = ctx.params.id
    return ctx.$axios.get('/api/list/' + id).then(res => ({ content: res.data.content }))
  },
  data () {
    return {
      id: this.$route.params.id
    }
  },
  methods: {
    editSbt () {
      const content = this.content
      this.$axios.put('/api/list/' + this.id, { content }).then((res) => {
        this.$router.push({ path: '/' })
      })
    }
  }
}
</script>

<style scoped>

</style>
